package com.cloud.drore.eboss.operation.mapper.provider;


import com.cloud.drore.eboos.common.constant.CommonConstant;
import com.cloud.drore.eboss.operation.entity.Merchant;
import com.cloud.drore.eboss.operation.entity.po.DistributorInfoPo;
import com.cloud.drore.eboss.operation.entity.po.MerchantPo;

/**
 * 浙江卓锐科技股份有限公司 版权所有  Copyright 2018<br>
 *
 * @Description: <br>
 * @Project: eboos <br>
 * @CreateDate: Created in 2018/1/6 0006 下午 1:12 <br>
 * @Author: <a href="410508961@qq.com">夏凯</a>
 */
public class MerchantProvider {

    /**
     * @param merchant
     * @ClassName: MerchantProvider
     * @Return: java.lang.String
     * @Decription: 商户状态已审核通过修改基本信息
     * @CreateDate: Created in 2018/1/10 0010 下午 12:07
     * @Author: <a href="410508961@qq.com">夏凯</a>
     * @Modify:
     */
    public String updateSql(Merchant merchant) {
        String sql = "update eboos_merchant set ";
        int count = 0;
        if (!"".equals(merchant.getLinkMan())) {
            if (count != 0) {
                sql += ",";
            }
            sql += "link_man='" + merchant.getLinkMan() + "'";
            count++;
        }
        if (!"".equals(merchant.getMobile())) {
            if (count != 0) {
                sql += ",";
            }
            sql += "mobile='" + merchant.getMobile() + "'";
            count++;
        }
        if (!"".equals(merchant.getTelephone())) {
            if (count != 0) {
                sql += ",";
            }
            sql += "telephone='" + merchant.getTelephone() + "'";
            count++;
        }
        if (!"".equals(merchant.getEmailAddress())) {
            if (count != 0) {
                sql += ",";
            }
            sql += "email_address='" + merchant.getEmailAddress() + "'";
            count++;
        }
        if (!"".equals(merchant.getPostalAddressProvince())) {
            if (count != 0) {
                sql += ",";
            }
            sql += "postal_address_province='" + merchant.getPostalAddressProvince() + "'";
            count++;
        }
        if (!"".equals(merchant.getPostalAddressCity())) {
            if (count != 0) {
                sql += ",";
            }
            sql += "postal_address_city='" + merchant.getPostalAddressCity() + "'";
            count++;
        }
        if (!"".equals(merchant.getPostalAddressCounty())) {
            if (count != 0) {
                sql += ",";
            }
            sql += "postal_address_county='" + merchant.getPostalAddressCounty() + "'";
            count++;
        }
        if (!"".equals(merchant.getDetailAddress())) {
            if (count != 0) {
                sql += ",";
            }
            sql += "detail_address='" + merchant.getDetailAddress() + "'";
            count++;
        }

        sql += " where id='" + merchant.getId() + "'";
        return sql;
    }

    /**
     * @param po
     * @ClassName: MerchantProvider
     * @Return: java.lang.String
     * @Decription:分销商列表信息
     * @CreateDate: Created in 2018/1/29 17:23
     * @Author: <a href="1451173193@qq.com">杨亮</a>
     * @Modify:
     */
    public String getDistributorListSql(DistributorInfoPo po) {

        StringBuffer sql = new StringBuffer("");
        sql.append("select a.id,a.merchant_name distributor_name,a.merchant_num distributor_num, a.link_man,a.mobile,merchant_industry distributor_type from eboos_merchant a" +
                " where a.merchant_type='"+CommonConstant.MERCHANT_DISTRIBUTE+"' and a.merchant_state='"+ CommonConstant.MERCHANT_AUDIT_ALREADY+"'");
        if (po.getDistributorName() != null && !po.getDistributorName().equals("")) {
            sql.append(" and instr(a.merchant_name,'" + po.getDistributorName() + "')>0");
        }
        if (po.getDistributorNum() != null && !po.getDistributorNum().equals("")) {
            sql.append("  and instr(a.merchant_num,'" + po.getDistributorNum() + "')>0");

        }
        return sql.toString();
    }

    /**
     * @param mainId
     * @param mainId
     * @ClassName: MerchantProvider
     * @Return: java.lang.String
     * @Decription:根据产品id获取分销商关联关系列表
     * @CreateDate: Created in 2018/1/30 19:57
     * @Author: <a href="1451173193@qq.com">杨亮</a>
     * @Modify:
     */
    public String getDistributorListByTicketIdSql(Long mainId) {
        String sql = "select a.main_id,a.id relation_id,b.merchant_name distributor_name,a.sales_price, a.settlement_price,a.term_of_validity_start_time,a.term_of_validity_end_time from eboos_distributor_product_association a\n" +
                "left join eboos_merchant b on a.distributor_id=b.id\n" +
                "where b.merchant_state='"+ CommonConstant.MERCHANT_AUDIT_ALREADY+"'" +
                "and a.main_id=" + mainId;
        return sql;
    }



    /**
     * @param merchant
     * @ClassName: MerchantProvider
     * @Return: java.lang.String
     * @Decription: 根据商户类型和商户名称查询商户列表
     * @CreateDate: Created in 2018/3/5 0005 下午 4:25
     * @Author: <a href="410508961@qq.com">夏凯</a>
     * @Modify:
     */
    public String queryMerchantInitList(MerchantPo merchant) {

        StringBuffer sql = new StringBuffer("select merchant_name,merchant_type,merchant_character,merchant_industry," +
                "link_man,mobile,telephone,email_address,postal_address_province,postal_address_city,postal_address_county," +
                "detail_address,business_license_url,binding_contract_start,binding_contract_end,contract_attachment,merchant_state," +
                "merchant_manager,merchant_num from eboos_merchant where 1=1");

        if (!(null == merchant.getMerchantName() || ("").equals(merchant.getMerchantName()))) {
            sql.append(" and merchant_name='"+merchant.getMerchantName()+"'");
        }
        if (!(null == merchant.getMerchantType() || ("").equals(merchant.getMerchantType()))) {
            sql.append(" and merchant_type='"+merchant.getMerchantType()+"'");
        }
        return sql.toString();
    }


}
